﻿using AutoMapper.QueryableExtensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Volo.Abp.AutoMapper;
using Xms.Abp.ObjectMapping;

namespace Xms.Abp.AutoMapper
{
    public class AutoMapperXmsAutoObjectMappingProvider : AutoMapperAutoObjectMappingProvider, IXmsAutoObjectMappingProvider
    {
        public AutoMapperXmsAutoObjectMappingProvider(IMapperAccessor mapperAccessor)
            : base(mapperAccessor)
        {
        }

        public IQueryable<TDestination> ProjectTo<TSource, TDestination>(IQueryable<TSource> source, params Expression<Func<TDestination, object>>[] membersToExpand)
        {
            return source.ProjectTo(MapperAccessor.Mapper.ConfigurationProvider, membersToExpand);
        }

        public IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, object parameters, params Expression<Func<TDestination, object>>[] membersToExpand)
        {
            return source.ProjectTo(MapperAccessor.Mapper.ConfigurationProvider, parameters, membersToExpand);
        }
        public IQueryable<TDestination> ProjectTo<TSource, TDestination>(IQueryable<TSource> source, IDictionary<string, object> parameters, params string[] membersToExpand)
        {
            return source.ProjectTo<TDestination>(MapperAccessor.Mapper.ConfigurationProvider, parameters, membersToExpand);
        }
        public IQueryable ProjectTo(IQueryable source, Type destinationType)
        {
            return source.ProjectTo(destinationType, MapperAccessor.Mapper.ConfigurationProvider);
        }
        public IQueryable ProjectTo(IQueryable source, Type destinationType, IDictionary<string, object> parameters, params string[] membersToExpand)
        {
            return source.ProjectTo(destinationType, MapperAccessor.Mapper.ConfigurationProvider, parameters, membersToExpand);
        }
    }

    public class AutoMapperXmsAutoObjectMappingProvider<TContext> : AutoMapperAutoObjectMappingProvider<TContext>, IXmsAutoObjectMappingProvider<TContext>
    {
        public AutoMapperXmsAutoObjectMappingProvider(IMapperAccessor mapperAccessor)
            : base(mapperAccessor)
        {
        }

        public IQueryable<TDestination> ProjectTo<TSource, TDestination>(IQueryable<TSource> source, params Expression<Func<TDestination, object>>[] membersToExpand)
        {
            return source.ProjectTo(MapperAccessor.Mapper.ConfigurationProvider, membersToExpand);
        }

        public IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, object parameters, params Expression<Func<TDestination, object>>[] membersToExpand)
        {
            return source.ProjectTo(MapperAccessor.Mapper.ConfigurationProvider, parameters, membersToExpand);
        }
        public IQueryable<TDestination> ProjectTo<TSource, TDestination>(IQueryable<TSource> source, IDictionary<string, object> parameters, params string[] membersToExpand)
        {
            return source.ProjectTo<TDestination>(MapperAccessor.Mapper.ConfigurationProvider, parameters, membersToExpand);
        }
        public IQueryable ProjectTo(IQueryable source, Type destinationType)
        {
            return source.ProjectTo(destinationType, MapperAccessor.Mapper.ConfigurationProvider);
        }
        public IQueryable ProjectTo(IQueryable source, Type destinationType, IDictionary<string, object> parameters, params string[] membersToExpand)
        {
            return source.ProjectTo(destinationType, MapperAccessor.Mapper.ConfigurationProvider, parameters, membersToExpand);
        }
    }
}
